﻿using dz.u9.jky.schema.Common;
using dz.u9.jky.schema.Vendor;
using dz.util.core;
using Microsoft.AspNetCore.Mvc;

namespace dz.u9.webapi.Controllers
{
    /// <summary>
    /// 供应商接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class SupplierController : U9BaseController
    {
        [HttpPost]
        public async Task<U9CResult> Add(DzSupplierDTO dto)
        {
            if (dto.SupplierSites == null)
            {
                DzSupplierSiteDTO site = new DzSupplierSiteDTO();
                site.Code = dto.Code;
                site.Name = dto.Name;
                site.IsDefaultBillTo = true;
                site.IsPriceListModify = true;
                site.IsReceiptRuleModify = true;
                site.IsPayItemEditable = true;

                List<DzSupplierSiteDTO> sites = new List<DzSupplierSiteDTO>() { site};                

                dto.SupplierSites = sites;  
            }

            dto.IsPriceListModify = true;
            dto.IsReceiptRuleEditable = true;
            dto.IsPaymentTermModify = true;
            dto.IsAPConfirmTermEditable = true;
            dto.ReceiptRule = "100";
            dto.PaymentTerm = "YZ01";
            dto.IsTaxPrice = true;

            return await U9Invoke(JsonUtil.Serialize(dto), new ApiParm() { Url = "DzSupplier/Add", Desc = "供应商新增" });
        }

        [HttpPost]
        public async Task<U9CResult> Modify(DzSupplierDTO dto)
        {
            return await U9Invoke(JsonUtil.Serialize(dto), new ApiParm() { Url = "DzSupplier/Modify", Desc = "供应商修改" });
        }
    }
}
